package com.adinnet.api.dict.controller;


import com.adinnet.api.dict.model.form.DictForm;
import com.adinnet.api.dict.service.DictService;
import com.adinnet.core.PageResp;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 字典 前端控制器
 * </p>
 *
 * @author sunjianbo
 * @since 2019-11-05
 */
@RestController
@RequestMapping("/api/v1/dict")
public class DictController extends ApiController {
    @Autowired
    private DictService dictService;


    /**
     * 详情
     *
     * @param id
     * @return
     */
    @GetMapping("get")
    public R get(Integer id) {
        if (id == null) {
            return failed("id必传");
        }
        return success(dictService.getById(id));
    }

    /**
     * 列表
     *
     * @param form
     * @return
     */
    @GetMapping("list")
    public PageResp list(DictForm form) {
        if (StringUtils.isEmpty(form.getDictCode())) {
            return new PageResp("编码不能为空");
        }
        return dictService.queryList(form);
    }

}
